package com.xyhuo.leetcode;

public class QuickSort {


    public static void sort(int[] list) {

    }

    public static void quickSort(int left, int right, int[] list) {
        if (left < right) {
            int middle = middle(left, right, list);
            quickSort(left, middle - 1, list);
            quickSort(middle + 1, right, list);
        }
    }

    private static int middle(int left, int right, int[] list) {
        int index = left + 1;
        for (int i = index; i < right; i++) {
            if (list[i] < list[left]) {
                swap(list, index, i);
                index++;
            }
        }
        swap(list, index - 1, left);
        return index - 1;
    }

    private static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
